/*
 * @Author: hx 2542123711@QQ.com
 * @Date: 2024-11-20 10:48:32
 * @LastEditors: hx 2542123711@QQ.com
 * @LastEditTime: 2024-11-20 11:59:06
 * @FilePath: /class_process-communication/NamePipe/client.cc
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include<iostream>
#include"comm.hpp"

using namespace std;

int main()
{
    //1.client第一步打开管道文件
    pid_t fd = open(FIFO_FILE, O_WRONLY);
    if(fd < 0)
    {
        perror("client open");
        exit(FILE_OPEN_ERROR);
    }

    cout << "client open file done" << endl;

    //2.client向管道文件中写入
    string buffer;
    while(true)
    {
        cout << "plase Enter@ " <<endl;
        // cin >> buffer;
        getline(cin, buffer);
        write(fd, buffer.c_str(), buffer.size());
    }
   
    //3.关闭管道文件
    close(fd);

    return 0;
}
